﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;


public partial class Controls_Tour_ctrQuickSearch : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.SetLableLanguage();
            this.Initdata();
        }
    }
    
    private void SetLableLanguage()
    {
        //btnSrch.Text = MultipleLanguage.BTN_SEARCH[Support.GetCurrentLanguage() - 1];
        //btnSearch.Text = MultipleLanguage.BTN_SEARCH[Support.GetCurrentLanguage() - 1];
        lblTour.Text =  MultipleLanguage.TOUR[Support.GetCurrentLanguage() - 1];
        lblHotel.Text = MultipleLanguage.HOTEL[Support.GetCurrentLanguage() - 1];
    }

    private void Initdata()
    {
        int nCountry = ConvertData.ConvertToInt(Request.QueryString[Config.COUNTRY]);
        if (nCountry == 0)
            nCountry = Config.COUNTRY_DEFAULT;
        BindDataToTourCat();
        BindDataToDuration();
        BindDataToCityDropdown(nCountry);
        BindDataStarRating();
    }
    private void BindDataStarRating()
    {
        ddlStarRating.Items.Insert(0, new ListItem(MultipleLanguage.DDL_SELECTHOTELRATE[nCurrentLang - 1], "0"));
        ddlStarRating.Items.Insert(1, new ListItem("1 Star", "1"));
        ddlStarRating.Items.Insert(2, new ListItem("2 Star", "2"));
        ddlStarRating.Items.Insert(3, new ListItem("3 Star", "3"));
        ddlStarRating.Items.Insert(4, new ListItem("4 Star", "4"));
        ddlStarRating.Items.Insert(5, new ListItem("5 Star", "5"));
    }
    private void BindDataToCityDropdown(int Country)
    {
        DataTable dtbCity = new DataTable();
        City objCity = new City();
        dtbCity = objCity.SearchByCountry(Country);
        ddlCity.DataSource = dtbCity;
        ddlCity.DataValueField = "CityID";
        int nCurrentLang = Support.GetCurrentLanguage();
        switch (nCurrentLang)
        {
            case 1:
                ddlCity.DataTextField = "CityName1";
                break;
            case 2:
                ddlCity.DataTextField = "CityName2";
                break;
            case 3:
                ddlCity.DataTextField = "CityName3";
                break;
        }
        ddlCity.DataBind();
        Utl.SetNonSelectToControl(ddlCity, MultipleLanguage.DDL_SELECTCITY[nCurrentLang - 1], MultipleLanguage.DDL_SELECTCITY[nCurrentLang - 1]);
    }
    private void BindDataToTourCat()
    {
        int nCountry = this.GetCountry();
        TourCategory objTourCat = new TourCategory();
        DataTable dtbCat = new DataTable();
        dtbCat = objTourCat.Search(0, nCountry);
        ddlTourCaterogy.DataSource = dtbCat;
        switch (nCurrentLang)
        {
            case 1:
                ddlTourCaterogy.DataTextField = "TourCategoryName1";
                break;
            case 2:
                ddlTourCaterogy.DataTextField = "TourCategoryName2";
                break;
            case 3:
                ddlTourCaterogy.DataTextField = "TourCategoryName3";
                break;
        }
        ddlTourCaterogy.DataValueField = "TourCategoryID";
        ddlTourCaterogy.DataBind();
        Utl.SetNonSelectToControl(ddlTourCaterogy, MultipleLanguage.DDL_SELECTCAT[nCurrentLang - 1], MultipleLanguage.DDL_SELECTCAT[nCurrentLang - 1]);
    }

    private void BindDataToDuration()
    {
        TourDuration objDuration = new TourDuration();
        ddlTourDuration.DataSource = objDuration.GetALL();
        int nCurrentLang = Support.GetCurrentLanguage();

        switch (nCurrentLang)
        {
            case 1:
                ddlTourDuration.DataTextField = "DurationDescription1";
                break;
            case 2:
                ddlTourDuration.DataTextField = "DurationDescription2";
                break;
            case 3:
                ddlTourDuration.DataTextField = "DurationDescription3";
                break;
        }
        ddlTourDuration.DataValueField = "DurationID";
        ddlTourDuration.DataBind();
        Utl.SetNonSelectToControl(ddlTourDuration, MultipleLanguage.DDL_SELECTDURATION[nCurrentLang - 1], MultipleLanguage.DDL_SELECTDURATION[nCurrentLang - 1]);
    }

    private int GetCountry()
    {
        int nCountry = 0;
        nCountry = ConvertData.ConvertToInt(Request.QueryString[Config.COUNTRY]);
        if (nCountry == 0)
            nCountry = Config.COUNTRY_DEFAULT;
        return nCountry;
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string sKeyWord = ConvertData.ConvertToString(txtSearchString.Text);
        string sTourCat = ConvertData.ConvertToString(ddlTourCaterogy.SelectedValue);
        string sTourDuration = ConvertData.ConvertToString(ddlTourDuration.SelectedValue);

        string sLink = Config.ROOT + Pages.FrontEnds.TOUR_LIST + "?"
            + Config.TOUR_DURATION + "=" + sTourDuration
            + "&" + Config.TOUR_CAT + "=" + sTourCat
            
            + "&" + Config.KEYWORD + "=" + sKeyWord;
        Response.Redirect(sLink);
    }
  
    protected void btnSrch_Click(object sender, ImageClickEventArgs e)
    {
        string sKeyWord = ConvertData.ConvertToString(txtKeyWord.Text);
        string sHotelCity = ConvertData.ConvertToString(ddlCity.SelectedValue);
        string sStarRating = ConvertData.ConvertToString(ddlStarRating.SelectedValue);
        string sLink = Config.ROOT + Pages.FrontEnds.HOTEL_LIST + "?"
            + Config.SEARCH_TYPE + "=" + "1"
            + "&" + Config.CITY + "=" + sHotelCity
            + "&" + Config.STARRATING + "=" + sStarRating
            + "&" + Config.KEYWORD + "=" + sKeyWord;
        Response.Redirect(sLink);
    }
}